package com.wakaca.design.pattern.behavioral.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * 促销的策略工厂
 * Created by wakac on 2019/4/3
 */
public class PromotionStrategyFactory {
    private static Map<String, PromotionStrategy> PROMOTION_STRATEGY_MAP = new HashMap<String, PromotionStrategy>();

    private static final PromotionStrategy NON_PROMOTION = new EmptyPromotionStrategy();

    static {
        PROMOTION_STRATEGY_MAP.put(promotionKey.LIJIAN, new LiJianPromotionStrategy());
        PROMOTION_STRATEGY_MAP.put(promotionKey.FANXIAN, new FanXianPromotionStrategy());
        PROMOTION_STRATEGY_MAP.put(promotionKey.MANJIAN, new ManJianPromotionStrategy());
    }

    private PromotionStrategyFactory() {}

    public static PromotionStrategy getPromotionStrategy(String promotionKey) {
        PromotionStrategy promotionStrategy = PROMOTION_STRATEGY_MAP.get(promotionKey);
        return promotionStrategy == null ?  NON_PROMOTION : promotionStrategy;
    }

    // 在声明常量的时候，他可以起到逻辑上分组的一个作用
    private interface promotionKey {
        final String LIJIAN = "LIJIAN";
        final String FANXIAN = "FANXIAN";
        final String MANJIAN = "MANJIAN";
    }
}
